;(function () {
  new Vue({
    el: '#wxGZHconfig',
    data: {
      permissions: JSON.parse(window.localStorage.getItem('permissions')),
      pnsData: [],
      pnsOP: {
        flag: false,
        id: null,
        url: null
      }
    },
    methods: {
      //获取公众号列表
      getWXpns: function () {
        var is = this;
        hlhttp.get({
          url: 'wx_pns',
          success: function (res) {
            is.pnsData = res;
          }
        })
      },
      //解绑微信弹出 pnsOP.flag = true
      delwxTc: function (id, img) {
        this.pnsOP = {flag: true,id: id,url: img}
      },
      //取消解绑微信
      cancelWxpns: function () {
        this.pnsOP = {flag: false,id: null,url: null}
      },
      //解绑微信公众号
      delWXpns: function () {
        var is = this;
        hlhttp.delete({
          url: 'wx_pns?wxpn_id='+is.pnsOP.id,
          success: function () {
            hl.toast('解绑成功')
            is.getWXpns()
            is.pnsOP = {flag: false,id: null,url: null}
          }
        })
      },
      //获取微信开发平台公众号授权链接
      getWXlink: function (type) {
        hlhttp.get({
          url: 'wxopen_auth_url',
          data: {type: type},
          success: function (res) {
            var url = window.location.href;
            var wxAuthUrl;

            if(url.indexOf('s.1hello.cn') !== -1){
              wxAuthUrl = window.location.protocol+'//message.1hello.cn/goToWxAuth.html?wxopenAuthUrl=' + res.wxopenAuthUrl;
            }else{
              wxAuthUrl = 'http://dev.fenzhitech.com/wbuild-saas-pc/goToWxAuth.html?wxopenAuthUrl=' + res.wxopenAuthUrl;
            }

            function openWin(url) {
              $('body').append($('<a href="'+url+'" target="_blank" id="openWin"></a>'))
              window.open(url)
              // document.getElementById("openWin").click();
              // $('#openWin').remove();
            }
            openWin(wxAuthUrl);
          }
        })
      },
      //配置跳转
      configTarge: function (val, id) {
        if (val == 'I') {
          hlUrlUtil.goTo('wxConfig', {id: id, ddtab:true})
        }
        if (val == 'O') {
          hlUrlUtil.goTo('wxConfig', {id: id, ddtab:true})
        }
      }
    },
    mounted: function () {
      this.getWXpns()
    }
  })
} ())
